package com.xindz.hgq.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.kingja.loadsir.callback.Callback;
import com.xindz.hgq.R;
import com.xindz.hgq.adapter.SimpleAdapter;
import com.xindz.hgq.base.BaseTitleActivity;
import com.xindz.hgq.base.BaseTitleToolBarActivity;
import com.xindz.hgq.base.options.BaseActivityOptions;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * @name HGQBase
 * @class name：com.xindz.hgq.title
 * @describe Title模式使用ToolBar封装了公共的Title,
 * 使用该模式Activity 的theme 需要windowActionBar false windowNoTitle true 或者继承 NoActionBar
 * ToolBar右上角三个小点颜色设置通过Theme  <item name="android:textColorSecondary">#ffffff</item> <item name="android:actionMenuTextColor">#ffffff</item>
 * menu弹出不覆盖ToolBar需要设置不覆盖锚点   <item name="overlapAnchor">false</item>  给ToolBar设置 app:popupTheme="@style/ToolbarPopupTheme"
 * 使用Title模式开发需要进行一下操作:
 * 一:继承BaseTitleActivity
 * 二:setOption方法中开启 new BaseActivityOptions().openTitle()
 * 三:使用父类中封装的方法进行设置 如 showLeftBack(); setToolBarScroll()等
 * @anthor XINDZ
 * @time 2018/1/12 11:09
 * @change
 * @chang time
 * @class describe
 */
public class TitleToolBarActivity extends BaseTitleToolBarActivity {


    @BindView(R.id.rcv_titleone)
    RecyclerView rcvTitleone;
    private Unbinder bind;
    private ArrayList<String> dataList = new ArrayList<>();
    private SimpleAdapter simpleAdapter;

    @Override
    public BaseActivityOptions setOption() {
        return new BaseActivityOptions().openTitle();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_title_one);
        bind = ButterKnife.bind(this);
        boolean openTitle = getOptions().isOpenTitle();
        boolean openLoadSir = getOptions().isOpenLoadSir();
        boolean openMVP = getOptions().isOpenMVP();
        initView();

        initData();

    }

    private void initView() {
        /**
         * 右侧Menu 点击事件
         */
        setMenuOnClickListerner(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                ToastUtils.showShort("点击Menu");
                return true;
            }
        });
        /**
         * 展示左侧返回键 并且点击finish界面
         */
        showLeftBack();
        /**
         * 设置Title可以滚出界面
         */
        setToolBarScroll();
    }

    private void initData() {
        rcvTitleone.setLayoutManager(new LinearLayoutManager(this));
        dataList.clear();
        dataList.add("Title模式使用方法见注释");
        for (int i = 0; i < 15; i++) {
            int a = i + 1;
            dataList.add("第 " + a + "    条");
        }
        simpleAdapter = new SimpleAdapter(R.layout.item_simple, dataList);
        rcvTitleone.setAdapter(simpleAdapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_one, menu);
        return true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (bind != null) bind.unbind();
    }

}
